package com.it2297.view;

import java.awt.CardLayout;
import java.awt.Dialog;
import java.awt.event.ActionListener;

import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.alee.extended.date.WebDateField;
import com.jgoodies.forms.factories.FormFactory;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.RowSpec;

@SuppressWarnings("serial")
public class UsedItemSearchDialog extends JDialog
{
	private final JPanel panel = new JPanel();
	private final JLabel lblTitle = new JLabel("Title:");
	private final JLabel lblDescription = new JLabel("Description:");
	private final JLabel lblItemCondition = new JLabel("Item Condition:");
	private final JLabel lblDatePosted = new JLabel("Date Posted");
	private final JTextField textField = new JTextField();
	private final JTextField textField_1 = new JTextField();
	private final JComboBox comboBox = new JComboBox();
	private final JComboBox comboBox_1 = new JComboBox();
	private final WebDateField textField_2 = new WebDateField();
	private final JButton btnSearch = new JButton("Search");
	private final JButton btnCancel = new JButton("Cancel");

	public UsedItemSearchDialog()
	{
		initGUI();
		pack();
	}

	private void initGUI()
	{
		setBounds(100, 100, 480, 320);
		setLocationRelativeTo(null);
		setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
		getContentPane().setLayout(new CardLayout(0, 0));

		getContentPane().add(panel, "name_6339318061810");
		panel.setLayout(new FormLayout(new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, FormFactory.MIN_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("min:grow"), FormFactory.RELATED_GAP_COLSPEC, FormFactory.MIN_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, }, new RowSpec[] { FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, }));

		panel.add(lblTitle, "2, 2, right, default");

		panel.add(textField, "4, 2, 5, 1, fill, default");

		panel.add(lblDescription, "2, 4, right, default");

		panel.add(textField_1, "4, 4, 5, 1, fill, default");

		panel.add(lblItemCondition, "2, 6, right, default");
		comboBox.setModel(new DefaultComboBoxModel(new String[] { "NOT SELECTED" }));

		panel.add(comboBox, "4, 6, fill, default");

		panel.add(lblDatePosted, "2, 8, right, default");
		comboBox_1.setModel(new DefaultComboBoxModel(new String[] { "NOT SELECTED", "EXACTLY", "BEFORE", "AFTER" }));

		panel.add(comboBox_1, "4, 8, fill, default");
		textField_2.setEnabled(false);
		textField_2.setPreferredWidth(150);

		panel.add(textField_2, "6, 8, 3, 1, fill, default");
		btnCancel.setIcon(new ImageIcon(UsedItemSearchDialog.class.getResource("/com/alee/extended/filechooser/icons/cancel.png")));

		panel.add(btnCancel, "6, 10");
		btnSearch.setIcon(new ImageIcon(UsedItemSearchDialog.class.getResource("/com/alee/extended/ninepatch/icons/min.png")));

		panel.add(btnSearch, "8, 10");
	}

	public String getTitleKeywords()
	{
		return textField.getText();
	}

	public String getDescriptionKeywords()
	{
		return textField_1.getText();
	}

	public void addSearchActionListener(ActionListener actionListener)
	{
		btnSearch.addActionListener(actionListener);
	}

	public void reset()
	{
		textField.setText(null);
		textField_1.setText(null);
		textField_2.setText(null);
	}

	public void addCancelActionListener(ActionListener actionListener)
	{
		btnCancel.addActionListener(actionListener);
	}
}
